package com.vencent.spring.bean;

import java.beans.PropertyDescriptor;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessorAdapter;

/**
 * InstantiationAwareBeanPostProcessorAdapter 实现了InstantiationAwareBeanPostProcessor，
 * InstantiationAwareBeanPostProcessor 继承了BeanPostProcessor
 * @author 1d
 *
 */
public class MyInstantiationAwareBeanPostProcessor extends InstantiationAwareBeanPostProcessorAdapter {

	public MyInstantiationAwareBeanPostProcessor() {
		// TODO Auto-generated constructor stub
		super();
		System.out.println("----容器级接口----");
		System.out.println("MyInstantiationAwareBeanPostProcessor的构造方法");
	}
	
	/**
	 * 实例化之后，一般用于代理
	 */
	@Override
	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("----容器级接口----");
		System.out.println("MyInstantiationAwareBeanPostProcessor的postProcessAfterInitialization方法");
		return super.postProcessAfterInitialization(bean, beanName);
	}
	
	/**
	 * 实例化之前，一般用于代理
	 */
	@Override
	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("----容器级接口----");
		System.out.println("MyInstantiationAwareBeanPostProcessor的postProcessBeforeInitialization方法");
		return super.postProcessBeforeInitialization(bean, beanName);
	}
	
	/**
	 * return 获取给bean属性赋值的集合
	 * 在工厂类给bean的setter方法之前，用于设置一些属性值 。
	 * 用来检查所以的依赖关系是否正确。
	 * for example based on a "Required" annotation on bean property setters
	 */
	@Override
	public PropertyValues postProcessPropertyValues(PropertyValues pvs, PropertyDescriptor[] pds, Object bean,
			String beanName) throws BeansException {
		// TODO Auto-generated method stub
		System.out.println("----容器级接口----");
		System.out.println("MyInstantiationAwareBeanPostProcessor的postProcessPropertyValues方法");
		return super.postProcessPropertyValues(pvs, pds, bean, beanName);
	}
}
